
function polygonCollision() {
    let canvas = document.getElementById("_canvas");
    let ctx = canvas.getContext("2d");
    let engine = new Engine(ctx);
    let layer = new Layer(ctx); 
    
    layer.create = function () {
        let polygon = new PolygonObject();
        polygon.radius = 100;
        polygon.x = 100;
        polygon.y = 100;
        polygon.degeCount = 7;
        polygon.addComponent(new GameComponent.MouseDrag());
        layer.addObject(polygon);

        let polygon2 = new PolygonObject();
        polygon2.radius = 200;
        polygon2.x = 700;
        polygon2.y = 300;
        polygon2.degeCount = 8;
        polygon2.addComponent(new GameComponent.MouseDrag());
        layer.addObject(polygon2);

        let tip = new TextObject();
        tip.x = 400;
        tip.y = 400;
        layer.addObject(tip);
        polygon.update = function () {
            if (CollisionUtil.metting(polygon, polygon2)) {
                polygon.strokeStyle = 'red';
                polygon2.strokeStyle = 'red';
                tip.text = '别碰我';
            } else {
                tip.text = '';
                polygon.strokeStyle = 'black';
                polygon2.strokeStyle = 'black';
            }
        }
    }
    engine.addLayer(layer);
    engine.run();
    return engine;
}
